#include "widget.h"
#include "ui_widget.h"
#include<QObject>
#include<qDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //使用事件过滤器
    //1.给label安装事件过滤器
    ui->label->installEventFilter(this);
}

Widget::~Widget()
{
    delete ui;
}

//2.重写虚函数
bool Widget::eventFilter(QObject *watched, QEvent *event)//参数：watched触发对象
{
    //
    if(watched==ui->label)
    {
        if(event->type()==QEvent::MouseButtonPress||event->type()==QEvent::MouseButtonDblClick)
        {
            qDebug()<<"左键按下eventFilter";
            return true;
        }

    }
    //交给其他父类处理
    return QWidget::eventFilter(watched,event);
}
